package com.study.web;

import com.study.utils.SysUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Slf4j
@EnableRedisHttpSession// spring session
@Controller
@RequestMapping("session")
public class SpringSessionController {

    @ResponseBody
    @GetMapping("add")
    public String addSession(HttpSession session) {
        session.setAttribute("sesName", "session测试");
        return SysUtils.getDateStr();
    }

    @ResponseBody
    @GetMapping("get")
    public String getSessionData(HttpSession session) {
        String sesName = (String) session.getAttribute("sesName");
        log.info("sesName ={}", sesName);
        return sesName;
    }
}
